package com.example.demo.controller;

import java.util.List;

import com.example.comon.domain.R;
import com.example.demo.domain.Bo.MenuListBo;
import com.example.demo.domain.Bo.RoleListBo;
import com.example.demo.domain.Bo.addMenuBo;
import com.example.demo.domain.Bo.addRoleBo;
import com.example.demo.domain.Menu;
import com.example.demo.domain.Role;
import com.example.demo.domain.Vo.menuListVo;
import com.example.demo.domain.Vo.roleListVo;
import com.example.demo.service.IMenuService;
import com.example.demo.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/role")
@Api(value = "role",tags = "角色")
public class RoleController {
    @Autowired
    private IRoleService roleService;

    @GetMapping("/getRoleList")
    @ApiOperation("获取角色列表")
    public R<List<roleListVo>> getRoleList(RoleListBo bo){
        Role role = new Role();
        role.setId(bo.getId());
        role.setName(bo.getName());
        List<roleListVo> list =roleService.selectRole(role);
        return R.success(list);
    }

    @PostMapping("/addRole")
    @ApiOperation("增加角色")
    public R<Role> addRole(@RequestBody addRoleBo bo){
        Role role = new Role();
        role.setName(bo.getName());
        role.setRemarks(bo.getRemarks());
        role.setCreate_by(bo.getCreated_by());
        role.setCreate_time(bo.getCreated_time());
        role.setUpdate_by(bo.getUpdate_by());
        role.setUpdate_time(bo.getUpdate_time());
        roleService.insertRole(role);
        return R.success(role);
    }

    @PostMapping("/updateRoleById")
    @ApiOperation("修改角色")
    public R updateRoleById(@RequestBody Role role){
        roleService.updateRoleById(role);
        return R.success();
    }

    @DeleteMapping("/delRoleById")
    @ApiOperation("删除角色")
    public R delRoleById(String id){
        roleService.delRoleById(id);
        return R.success();
    }

}
